package com.hz.controller;

import com.hz.dao.*;
import com.hz.pojo.Earnings;
import com.hz.pojo.WashMachine;
import com.hz.utils.DateUtils;
import com.hz.utils.HomePageUtils;
import com.hz.utils.MassageJsons;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.List;

@RestController
@RequestMapping("/HomePage")
public class HomePageController {
    @Resource
    EarningsDao earningsDao;
    @Resource
    StringRedisTemplate stringRedisTemplate;
    @Resource
    AdminDao adminDao;
    @Resource
    OrderDao orderDao;
    @Resource
    WashHouseDao washHouseDao;
    @Resource
    WashMachineDao washMachineDao;
    @RequestMapping("/getHomePageInfo")
    public HomePageUtils getHomePageInfo(){
        //用户总数
        Integer sum_user_count = 0;
        //洗衣房总数
        Integer sum_washhouse_count = 0;
        //洗衣机总数
        Integer sum_washmachine_count = 0;
        //订单总数
        Integer sum_order_count = 0;
        //平台总收益
        Double sum_earnings = 0.00;
        DecimalFormat df   = new DecimalFormat("######0.00");
        List list = null;
        try {
            sum_user_count = adminDao.getUserCounts(null);
            list = washHouseDao.getWashHouseAllInfo();
            sum_washhouse_count = list.size();
            sum_washmachine_count = washMachineDao.getWashMachineCount();
            sum_order_count=orderDao.getOrdeCoune();
            sum_earnings=Double.parseDouble(stringRedisTemplate.opsForValue().get("HN520"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new HomePageUtils(sum_user_count,sum_washhouse_count,sum_washmachine_count,sum_order_count,df.format(sum_earnings));
    }

    /**
     * 获取最近七天的记录
     * @return
     */
    @RequestMapping("/getAllEarnings")
    public MassageJsons getAllEarnings(){
        List<Earnings> listEarnings = null;
        try {
            listEarnings = earningsDao.getAllEarnings(DateUtils.getServen(),DateUtils.getCurrentTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons("0","请求成功",listEarnings);
    }

    @RequestMapping("/getAllEarningsMonth")
    public MassageJsons getAllEarningsMonth(Integer month){
        List<Earnings> listEarnings = null;
        try {
            switch (month){
                case 1:
                    listEarnings = earningsDao.getAllEarnings("2020-01-01 00:00:00","2020-01-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 2:
                    listEarnings = earningsDao.getAllEarnings("2020-02-01 00:00:00","2020-02-28 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 3:
                    listEarnings = earningsDao.getAllEarnings("2020-03-01 00:00:00","2020-03-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 4:
                    listEarnings = earningsDao.getAllEarnings("2020-04-01 00:00:00","2020-04-30 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 5:
                    listEarnings = earningsDao.getAllEarnings("2020-05-01 00:00:00","2020-05-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 6:
                    listEarnings = earningsDao.getAllEarnings("2020-06-01 00:00:00","2020-06-30 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 7:
                    listEarnings = earningsDao.getAllEarnings("2020-07-01 00:00:00","2020-07-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 8:
                    listEarnings = earningsDao.getAllEarnings("2020-08-01 00:00:00","2020-08-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 9:
                    listEarnings = earningsDao.getAllEarnings("2020-09-01 00:00:00","2020-09-30 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 10:
                    listEarnings = earningsDao.getAllEarnings("2020-10-01 00:00:00","2020-10-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 11:
                    listEarnings = earningsDao.getAllEarnings("2020-11-01 00:00:00","2020-11-30 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                case 12:
                    listEarnings = earningsDao.getAllEarnings("2020-12-01 00:00:00","2020-12-31 23:59:59");
                    return new MassageJsons("0","请求成功",listEarnings);
                default:
                    return new MassageJsons("1","该月份不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }




}
